//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// Set a flag to true or false.
/// </summary>
[AddComponentMenu("ViNo/Nodes/Label_Jump/FlagSet")]
[ System.Serializable ]
public class FlagSetNode : ViNode {	
	public ViNoFlagType m_FlagType;
	public string m_FlagName;
	
	public override void ToScenarioScript( ref System.Text.StringBuilder sb ){
		Hashtable attr = new Hashtable();
		attr[ "name" ] = m_FlagName;
		attr[ "value" ] = m_FlagType.ToString().ToLower();
//		attr[ "type"] = "boolean";		
	 	string script = GetScript( "setflag" , attr );
		sb.Append( script );
	}

	public override void ToByteCode( ByteCodes code ){
		List<byte> byteList = new List<byte>();
		
		AddNodeCode( byteList );
		
		if( m_FlagType == ViNoFlagType.TRUE ){
			ByteCodeScriptTools.AddTextLiteralCode( byteList , m_FlagName );
			byteList.Add( Opcode.FLAG_ON );
		}
		else{
			ByteCodeScriptTools.AddTextLiteralCode( byteList , m_FlagName );
			byteList.Add( Opcode.FLAG_OFF );
		}
		code.Add( byteList.ToArray() );		

		ToByteCodeInternal( code );
	}	
	
}
